//
//  UIBarButtonItem+WZB.m
//  百思不得姐
//
//  Created by apple on 15/12/28.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "UIBarButtonItem+WZB.h"
#import "UIView+FrameChange.h"

@implementation UIBarButtonItem (WZB)

+ (UIBarButtonItem *)barButtonItemWithNorImageName:(NSString *)norImageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action title:(NSString *)title{
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    
//    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
    
    [btn setImage:[[UIImage imageNamed:norImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:highImageName] forState:UIControlStateHighlighted];
    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    if (!title) {
        CGSize size = [title sizeWithFont:btn.titleLabel.font];
        btn.height = size.height;
        btn.width = size.width + btn.imageView.height + 20;
        
        // 让按钮内部所有内容左对齐
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }else{
        btn.frame = CGRectMake(.0, 0, 35, 35);
        
    }
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

@end
